<template>
	<view class="container">
		<!-- 优惠券状态筛选 -->
		<view class="card mb-20">
			<scroll-view scroll-x class="scroll-x">
				<view class="flex">
					<view class="status-item" :class="{active: activeStatus === index}" v-for="(item, index) in statusList" :key="index" @click="switchStatus(index)">
						{{ item }}
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 优惠券列表 -->
		<view class="coupon-list">
			<view class="coupon-item card mb-20" v-for="(item, index) in couponList" :key="index">
				<view class="flex">
					<view class="coupon-price flex flex-direction-column align-center justify-center" :class="item.status === '已使用' || item.status === '已过期' ? 'disabled' : ''">
						<text style="font-size: 36rpx;">¥</text>
						<text style="font-size: 60rpx; font-weight: bold;">{{ item.amount }}</text>
					</view>
					<view class="flex-1" style="margin-left: 30rpx;">
						<text class="block" style="font-weight: bold; font-size: 32rpx;">{{ item.title }}</text>
						<text class="block text-gray mt-10">满{{ item.minAmount }}元可用</text>
						<text class="block text-gray mt-10">有效期至{{ item.expireDate }}</text>
						<text class="block text-gray mt-10">{{ item.scope }}</text>
					</view>
					<view class="flex flex-direction-column align-center justify-center">
						<text class="button" :class="item.status === '已使用' || item.status === '已过期' ? 'button-disabled' : ''" 
							@click="useCoupon(item)" 
							:style="item.status === '已使用' || item.status === '已过期' ? 'background: #ccc;' : ''">
							{{ item.status }}
						</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty-container text-center" v-if="couponList.length === 0">
			<text class="iconfont icon-coupon" style="font-size: 100rpx; color: #ccc;"></text>
			<text class="block mt-20">暂无优惠券</text>
			<text class="block text-gray mt-10">快去领取优惠券吧</text>
			<view class="button mt-20" @click="getCoupon">去领取</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeStatus: 0,
				statusList: ['全部', '未使用', '已使用', '已过期'],
				couponList: [
					{
						id: 1,
						title: '新人专享券',
						amount: 50,
						minAmount: 100,
						expireDate: '2023-12-31',
						scope: '全场通用',
						status: '未使用'
					},
					{
						id: 2,
						title: '酒店专享券',
						amount: 100,
						minAmount: 300,
						expireDate: '2023-07-31',
						scope: '仅限酒店预订使用',
						status: '未使用'
					},
					{
						id: 3,
						title: '景点门票券',
						amount: 20,
						minAmount: 50,
						expireDate: '2023-06-10',
						scope: '仅限门票购买使用',
						status: '已过期'
					},
					{
						id: 4,
						title: '满减优惠券',
						amount: 30,
						minAmount: 150,
						expireDate: '2023-08-15',
						scope: '全场通用',
						status: '已使用'
					}
				]
			}
		},
		methods: {
			switchStatus(index) {
				this.activeStatus = index;
				// 实际开发中这里需要重新请求对应状态的优惠券数据
			},
			useCoupon(item) {
				if (item.status === '未使用') {
					uni.showToast({
						title: '使用优惠券功能开发中',
						icon: 'none'
					})
				} else if (item.status === '已使用') {
					uni.showToast({
						title: '该优惠券已使用',
						icon: 'none'
					})
				} else if (item.status === '已过期') {
					uni.showToast({
						title: '该优惠券已过期',
						icon: 'none'
					})
				}
			},
			getCoupon() {
				uni.showToast({
					title: '领取优惠券功能开发中',
					icon: 'none'
				})
			}
		}
	}
</script>

<style>
	.scroll-x {
		white-space: nowrap;
		width: 100%;
	}
	
	.status-item {
		display: inline-block;
		padding: 15rpx 30rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		background: #f5f5f5;
	}
	
	.status-item.active {
		background: #4caf50;
		color: #fff;
	}
	
	.coupon-price {
		width: 150rpx;
		color: #ff3b30;
	}
	
	.coupon-price.disabled {
		color: #ccc;
	}
	
	.button-disabled {
		background: #ccc !important;
	}
	
	.empty-container {
		padding-top: 200rpx;
	}
</style>